/**
 * @author Ahammer
 * @date    2010 02
 * @@update 2011 01 added 16bit option
 */

/*
 * This file is part of Iqm.
 * Copyright (c) 2010-2011 Helmut Ahammer
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package opgui;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.text.DecimalFormat;
import javax.media.jai.ParameterBlockJAI;
import javax.media.jai.PlanarImage;
import javax.swing.ButtonGroup;
import javax.swing.InputVerifier;
import javax.swing.JComponent;
import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JScrollBar;
import javax.swing.JSpinner;
import javax.swing.JToolBar;
import javax.swing.SpinnerModel;
import javax.swing.SpinnerNumberModel;
import javax.swing.SwingUtilities;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.text.InternationalFormatter;
import main.IqmTools;
import main.Tank;


public class IqmCreateImageGUI  extends IqmOperatorJFrame
						  		   implements IqmOperatorGUIBuilder,
						  		   ActionListener, 
						  		   ChangeListener {

	private  ParameterBlockJAI   pbJAI      = null;  //  @jve:decl-index=0:
	//public  ImgProcFuncJFrame  opGUIFrame = null;
	//private IqmCreateImageGUI  opGUIFrame = null;  //actionPerformed events werden in dieser Klasse abgehandelt
	
	private JPanel 				  jPanelWidth		= null;	
	private JLabel				  jLabelWidth		= null;
	private JFormattedTextField   jFormattedTextFieldWidth  = null;	
	private JSpinner			  jSpinnerWidth 	= null;
	private JPanel 				  jPanelHeight	    = null;	
	private JLabel				  jLabelHeight	    = null;
	private JFormattedTextField   jFormattedTextFieldHeight = null;	
	private JSpinner			  jSpinnerHeight 	= null;
	
	private JRadioButtonMenuItem  buttRandom        = null;	
	private JRadioButtonMenuItem  buttGauss         = null;	
	private JRadioButtonMenuItem  buttConst         = null;	
	private JRadioButtonMenuItem  buttSin           = null;	
	private JRadioButtonMenuItem  buttCos           = null;		
	private JRadioButtonMenuItem  buttMethodHidden  = null;
	private JToolBar              jToolBarMethod    = null;
	private ButtonGroup           buttGroupMethod   = null;
		
	private JPanel 				  jPanelConst		= null;	
	private JLabel				  jLabelConst		= null;
	private JFormattedTextField   jFormattedTextFieldConst  = null;	
	private JSpinner			  jSpinnerConst 	= null;
	private JPanel 				  jPanelOmega	    = null;	
	private JLabel				  jLabelOmega	    = null;
	private JFormattedTextField   jFormattedTextFieldOmega = null;	
	private JSpinner			  jSpinnerOmega 	= null;
	
	private JRadioButtonMenuItem  butt8Bit         = null;	
	private JRadioButtonMenuItem  butt16Bit        = null;	
	private JRadioButtonMenuItem  buttHiddenOutBit = null;
	private JToolBar              jToolBarOutBit   = null;
	private ButtonGroup           buttGroupOutBit  = null;

	
	/**
	 * constructor
	 */
	public IqmCreateImageGUI() {

	}

	
	/**
	 * This method sets all  variables to null
	 */
	private void resetVariables(){
		pbJAI         = null; 
		//opGUIFrame = null; 
		
		//jToolBarRGB  = null;

	}
	/**
	 * This method sets all parameters to null
	 */
	private void resetParameters(){
		//butt       = null;
		//butt       = null;
	}

	/**
	 * This method sets the current parameter block to the argument
	 * @param ParameterBlockJAI pb
	 */
	@Override
	public void setParameterBlock(ParameterBlockJAI arg){
		pbJAI = arg;
		IqmTools.setCurrParameterBlockJAI(pbJAI);	
	}
	/**
	 * This method sets the current parameter block
	 * The individual values of the GUI  current ParameterBlock
	 *
	 */
	@Override
	public void setParameterBlock(){
		pbJAI.setParameter("Width",  ((Number)jSpinnerWidth.getValue()).intValue());
		pbJAI.setParameter("Height", ((Number)jSpinnerHeight.getValue()).intValue());

		if (buttRandom.isSelected()) pbJAI.setParameter("Method", 0);
		if (buttGauss.isSelected())  pbJAI.setParameter("Method", 1);
		if (buttConst.isSelected())  pbJAI.setParameter("Method", 2);
		if (buttSin.isSelected())    pbJAI.setParameter("Method", 3);
		if (buttCos.isSelected())    pbJAI.setParameter("Method", 4);
		
		pbJAI.setParameter("Const",  ((Number)jSpinnerConst.getValue()).intValue());
		pbJAI.setParameter("Omega", ((Number)jSpinnerOmega.getValue()).intValue());
		
		if (butt8Bit.isSelected())   pbJAI.setParameter("OutBit", 0);
		if (butt16Bit.isSelected())  pbJAI.setParameter("OutBit", 1);
		
		IqmTools.setCurrParameterBlockJAI(pbJAI);	
	}
	
	/**
	 * This method sets the current parameter values
	 *
	 */
	@Override
	public void setParameterValues(){
		
//		//there is no need for a current image
//		int idx = IqmTools.getCurrManagerImgIndex();
//	    PlanarImage pi = Tank.getCurrentTankImageAt(idx); 
//	    if (pi == null){
//	    	   System.out.println("IqmCreateImageGUI: Current image not defined");
//	    	   return;
//	    }
      
		if (pbJAI.getIntParameter("Method") == 0) buttRandom.setSelected(true);
		if (pbJAI.getIntParameter("Method") == 1) buttGauss.setSelected(true);
		if (pbJAI.getIntParameter("Method") == 2) buttConst.setSelected(true);
		if (pbJAI.getIntParameter("Method") == 3) buttSin.setSelected(true);
		if (pbJAI.getIntParameter("Method") == 4) buttCos.setSelected(true);
		
		
	    jSpinnerWidth.removeChangeListener(this);	    	    
	    jSpinnerHeight.removeChangeListener(this);	 
	    jSpinnerConst.removeChangeListener(this);	    	    
	    jSpinnerOmega.removeChangeListener(this);	 
	    jSpinnerWidth.setValue(pbJAI.getIntParameter("Width"));
	    jSpinnerHeight.setValue(pbJAI.getIntParameter("Height"));
	    jSpinnerConst.setValue(pbJAI.getIntParameter("Const"));
	    jSpinnerOmega.setValue(pbJAI.getIntParameter("Omega"));
	    jSpinnerWidth.addChangeListener(this);
	    jSpinnerHeight.addChangeListener(this);
	    jSpinnerConst.addChangeListener(this);
	    jSpinnerOmega.addChangeListener(this);
	    
		if (buttConst.isSelected()){
			jSpinnerConst.setEnabled(true);
		}else{
			jSpinnerConst.setEnabled(false);
		}
		if (buttSin.isSelected() || buttCos.isSelected()){
			jSpinnerOmega.setEnabled(true);
		}else{
			jSpinnerOmega.setEnabled(false);
		}
		
		if (pbJAI.getIntParameter("OutBit") == 0) butt8Bit.setSelected(true);
		if (pbJAI.getIntParameter("OutBit") == 1) butt16Bit.setSelected(true);
    
	}

	/**
	 * This method creates and shows the GUI
	 */
	@Override
	public void createIqmOperatorGUI() {
		//System.out.println("IqmCreateImage: createAndShowGUI invoked");
		//opGUIFrame = new IqmCreateImageGUI();      //actionPerforemd events werden in dieser Klasse abgehandelt
		//opGUIFrame.getJContentPane();
		this.initialize(); //Aufruf von ImgProcFuncJFrame
		this.setTitle("CreateImage");
		//PlanarImage pi = Tank.getCurrentTankImageAt(IqmTools.getCurrManagerImgIndex());	
		//this.setSize(dim.width, dim.height+280);
		//this.setPreferredSize(new Dimension(800, 600));
		this.getJContentPane().add(getJPanelWidth(),     getGridBagConstraintsWidth());
		this.getJContentPane().add(getJPanelHeight(),    getGridBagConstraintsHeight());
		this.getJContentPane().add(getJToolBarMethod(),  getGridBagConstraintsButtonMethodGroup());
		this.getJContentPane().add(getJPanelConst(),     getGridBagConstraintsConst());
		this.getJContentPane().add(getJPanelOmega(),     getGridBagConstraintsOmega());
		this.getJContentPane().add(getJToolBarOutBit(),  getGridBagConstraintsButtonOutBitGroup());

		this.pack();
		//this.repaint();
		if (pbJAI == null) pbJAI = new ParameterBlockJAI("IqmCreateImage");  //nur wenn das erste mal aufgerufen
		//pbJAI = new ParameterBlockJAI("iqmthreshold"); //immer der default Block
		IqmTools.setCurrParameterBlockJAI(pbJAI);
		this.setParameterValues();
	
	}
	private GridBagConstraints getGridBagConstraintsWidth(){
		GridBagConstraints gridBagConstraintsWidth = new GridBagConstraints();
		gridBagConstraintsWidth.gridx = 1;
		gridBagConstraintsWidth.gridy = 5;
		gridBagConstraintsWidth.gridwidth = 1;//?
		gridBagConstraintsWidth.insets = new Insets(20,0,0,0);  //top left bottom right
		//gridBagConstraintsWidth.fill = GridBagConstraints.BOTH;
		return gridBagConstraintsWidth;
	}
	private GridBagConstraints getGridBagConstraintsHeight(){
		GridBagConstraints gridBagConstraintsHeight = new GridBagConstraints();
		gridBagConstraintsHeight.gridx = 2;
		gridBagConstraintsHeight.gridy = 5;
		gridBagConstraintsHeight.gridwidth = 2;//?
		gridBagConstraintsHeight.insets = new Insets(20,10,0,0);  //top left bottom right
		//gridBagConstraintsHeight.fill = GridBagConstraints.BOTH;
		return gridBagConstraintsHeight;
	}
	private GridBagConstraints getGridBagConstraintsButtonMethodGroup(){
		GridBagConstraints gridBagConstraintsButtonMethodGroup = new GridBagConstraints();
		gridBagConstraintsButtonMethodGroup.gridx = 2;
		gridBagConstraintsButtonMethodGroup.gridy = 6;
		gridBagConstraintsButtonMethodGroup.gridwidth = 2;//?
		gridBagConstraintsButtonMethodGroup.insets = new Insets(10,0,0,0);  //top left bottom right		
		//gridBagConstraintsButtonMethodGroup.fill = GridBagConstraints.BOTH;
		return gridBagConstraintsButtonMethodGroup;
	}	
	private GridBagConstraints getGridBagConstraintsConst(){
		GridBagConstraints gridBagConstraintsConst = new GridBagConstraints();
		gridBagConstraintsConst.gridx = 1;
		gridBagConstraintsConst.gridy = 7;
		gridBagConstraintsConst.gridwidth = 1;//?
		gridBagConstraintsConst.insets = new Insets(10,0,0,0);  //top left bottom right
		//gridBagConstraintsConst.fill = GridBagConstraints.BOTH;
		return gridBagConstraintsConst;
	}
	private GridBagConstraints getGridBagConstraintsOmega(){
		GridBagConstraints gridBagConstraintsOmega = new GridBagConstraints();
		gridBagConstraintsOmega.gridx = 2;
		gridBagConstraintsOmega.gridy = 7;
		gridBagConstraintsOmega.gridwidth = 2;//?
		gridBagConstraintsOmega.insets = new Insets(10,10,0,0);  //top left bottom right
		//gridBagConstraintsOmega.fill = GridBagConstraints.BOTH;
		return gridBagConstraintsOmega;
	}
	private GridBagConstraints getGridBagConstraintsButtonOutBitGroup(){
		GridBagConstraints gridBagConstraintsButtonOutBitGroup = new GridBagConstraints();
		gridBagConstraintsButtonOutBitGroup.gridx = 1;
		gridBagConstraintsButtonOutBitGroup.gridy = 8;
		gridBagConstraintsButtonOutBitGroup.gridwidth = 3;//?
		gridBagConstraintsButtonOutBitGroup.insets = new Insets(10,0,20,0);  //top left bottom right		
		//gridBagConstraintsButtonOutBitGroup.fill = GridBagConstraints.BOTH;
		return gridBagConstraintsButtonOutBitGroup;
	}
	
	//------------------------------------------------------------------------------------------------------------------
	/**
	 * This method closes and destroys the GUI
	 * 
	 * @return void
	 */
//	public void destroyGUI() {
//		if (this != null){
//					
//			//this.closeAndDestroyGUI();
//			//resetVariables();
//			//folgendes geht auch!?
//			this.setVisible(false);
//			this.dispose();
//			//this = null;
//		}
//	}
	/**
	 * This method updates the GUI
	 * This method overrides IqmOperatorJFrame
	 */
	@Override
	public void updateIqmOperatorGUI(){
	
	}

	//-----------------------------------------------------------------------
//	class IntNumberVerifier extends InputVerifier { //damit muss Eingabe richtig sein 
//		@Override
//		public boolean verify(JComponent input) {
//		   JFormattedTextField ftf = (JFormattedTextField)input;
//		   JFormattedTextField.AbstractFormatter formatter = ftf.getFormatter();
//		   if (formatter != null) {
//		      String text = ftf.getText();
//		  	  try {
//				   text = text.replace(",", ".");
//				   Integer.valueOf(text);
//				   //Float.valueOf(text);
//					return true;
//			  } catch (NumberFormatException e) {
//					return false;
//			  }	 
//		   }
//		   return true;
//		}
//		public boolean shouldYieldFocus(JComponent input) {
//		System.out.println("NumberVerifier  shouldYieldFocus");
//
//          return verify(input);
//    }
//    }

	/**
	 * This method initializes jJPanelWidth	
	 * 	
	 * @return javax.swing.JPanel
	 */
	private JPanel getJPanelWidth() {
		if (jPanelWidth == null) {
			jPanelWidth = new JPanel();
			jPanelWidth.setLayout(new BorderLayout());		
			jLabelWidth = new JLabel("Width: ");
			jLabelWidth.setPreferredSize(new Dimension(50, 22));
			jLabelWidth.setHorizontalAlignment(JLabel.RIGHT);
			SpinnerModel sModel = new SpinnerNumberModel(0, 0, Integer.MAX_VALUE, 1); //init, min, max, step
			jSpinnerWidth = new JSpinner(sModel);
			jSpinnerWidth.setPreferredSize(new Dimension(60, 22));
			jSpinnerWidth.addChangeListener(this);
			JSpinner.DefaultEditor defEditor = (JSpinner.DefaultEditor)jSpinnerWidth.getEditor()  ;
			JFormattedTextField ftf = defEditor.getTextField() ;
			jFormattedTextFieldWidth = ftf;
			InternationalFormatter intFormatter = (InternationalFormatter)ftf.getFormatter() ;
			DecimalFormat decimalFormat = (DecimalFormat)intFormatter.getFormat() ;
			decimalFormat.applyPattern("#");  //decimalFormat.applyPattern("#,##0.0")  ;		
			jPanelWidth.add(jLabelWidth, 	 BorderLayout.WEST);
			jPanelWidth.add(jSpinnerWidth, BorderLayout.CENTER);			
		}
		return jPanelWidth;
	}
	/**
	 * This method initializes jJPanelHeight	
	 * 	
	 * @return javax.swing.JPanel
	 */
	private JPanel getJPanelHeight() {
		if (jPanelHeight == null) {
			jPanelHeight = new JPanel();
			jPanelHeight.setLayout(new BorderLayout());		
			jLabelHeight = new JLabel("Height: ");
			jLabelHeight.setHorizontalAlignment(JLabel.RIGHT);
			jLabelHeight.setPreferredSize(new Dimension(50, 22));
			SpinnerModel sModel = new SpinnerNumberModel(0, 0, Integer.MAX_VALUE, 1); //init, min, max, step
			jSpinnerHeight = new JSpinner(sModel);
			jSpinnerHeight.setPreferredSize(new Dimension(60, 22));
			jSpinnerHeight.addChangeListener(this);
			JSpinner.DefaultEditor defEditor = (JSpinner.DefaultEditor)jSpinnerHeight.getEditor()  ;
			JFormattedTextField ftf = defEditor.getTextField() ;
			jFormattedTextFieldHeight = ftf;
			InternationalFormatter intFormatter = (InternationalFormatter)ftf.getFormatter() ;
			DecimalFormat decimalFormat = (DecimalFormat)intFormatter.getFormat() ;
			decimalFormat.applyPattern("#");  //decimalFormat.applyPattern("#,##0.0")  ;		
			jPanelHeight.add(jLabelHeight, 	 BorderLayout.WEST);
			jPanelHeight.add(jSpinnerHeight, BorderLayout.CENTER);			
		}
		return jPanelHeight;
	}

	//--------------------------------------------------------------------------------------------
	/**
	 * This method initializes the Option: 
	 * 	
	 * @return javax.swing.JRadioButtonMenuItem	
	 */
	private  JRadioButtonMenuItem getJRadioButtonMenuButtRandom() {
		if (buttRandom == null) {
			buttRandom = new JRadioButtonMenuItem();
			buttRandom.setText("Random");
			buttRandom.setToolTipText("randomly distributed grey values");
			buttRandom.addActionListener(this);
			buttRandom.setActionCommand("parameter");
		}
		return buttRandom;
	}
	/**
	 * This method initializes the Option: 
	 * 	
	 * @return javax.swing.JRadioButtonMenuItem	
	 */
	private  JRadioButtonMenuItem getJRadioButtonMenuButtGauss() {
		if (buttGauss == null) {
			buttGauss = new JRadioButtonMenuItem();
			buttGauss.setText("Gauss");
			buttGauss.setToolTipText("gaussian distributed grey values");
			buttGauss.addActionListener(this);
			buttGauss.setActionCommand("parameter");
		}
		return buttGauss;
	}
	/**
	 * This method initializes the Option: 
	 * 	
	 * @return javax.swing.JRadioButtonMenuItem	
	 */
	private  JRadioButtonMenuItem getJRadioButtonMenuButtConst() {
		if (buttConst == null) {
			buttConst = new JRadioButtonMenuItem();
			buttConst.setText("Constant");
			buttConst.setToolTipText("constant grey values");
			buttConst.addActionListener(this);
			buttConst.setActionCommand("parameter");
		}
		return buttConst;
	}
	/**
	 * This method initializes the Option: 
	 * 	
	 * @return javax.swing.JRadioButtonMenuItem	
	 */
	private  JRadioButtonMenuItem getJRadioButtonMenuButtSin() {
		if (buttSin == null) {
			buttSin = new JRadioButtonMenuItem();
			buttSin.setText("Sin");
			buttSin.setToolTipText("sinus shaped grey values");
			buttSin.addActionListener(this);
			buttSin.setActionCommand("parameter");
		}
		return buttSin;
	}
	/**
	 * This method initializes the Option: 	
	 * @return javax.swing.JRadioButtonMenuItem	
	 */
	private  JRadioButtonMenuItem getJRadioButtonMenuButtCos() {
		if (buttCos == null) {
			buttCos = new JRadioButtonMenuItem();
			buttCos.setText("Cos");
			buttCos.setToolTipText("cosinus shaped grey values");
			buttCos.addActionListener(this);
			buttCos.setActionCommand("parameter");
		}
		return buttCos;
	}

	/**
	 * This method initializes the hidden option	
	 * 	
	 * @return javax.swing.JRadioButtonMenuItem	
	 */
	private  JRadioButtonMenuItem getJRadioButtonMenuButtMethodHidden() {
		if (buttMethodHidden == null) {
			buttMethodHidden = new JRadioButtonMenuItem();
			buttMethodHidden.setText("Hidden");
			buttMethodHidden.setVisible(false);
		}
		return buttMethodHidden;
	}
	/**
	 * This method initializes jJToolBarBar	
	 * 	
	 * @return javax.swing.JToolBar	
	 */
	private   JToolBar getJToolBarMethod() {
		if (jToolBarMethod== null) {
			jToolBarMethod = new JToolBar("Options");
			jToolBarMethod.setOrientation(1); // 0 Horizontal 1 Vertical orientation
			jToolBarMethod.add(getJRadioButtonMenuButtRandom());
			jToolBarMethod.add(getJRadioButtonMenuButtGauss());
			jToolBarMethod.add(getJRadioButtonMenuButtConst());
			jToolBarMethod.add(getJRadioButtonMenuButtSin());
			jToolBarMethod.add(getJRadioButtonMenuButtCos());
			jToolBarMethod.add(getJRadioButtonMenuButtMethodHidden());
			//jToolBarMethod.addSeparator();
			this.setButtonGroupMethod();	//Gruppieren der JRadioButtons
		}
		return jToolBarMethod;
	}
	private  void setButtonGroupMethod() {
		//if (ButtonGroup buttGroup == null) {
			buttGroupMethod = new ButtonGroup();
			buttGroupMethod.add(buttRandom);
			buttGroupMethod.add(buttGauss);
			buttGroupMethod.add(buttConst);
			buttGroupMethod.add(buttSin);
			buttGroupMethod.add(buttCos);
			buttGroupMethod.add(buttMethodHidden);
	}
	//--------------------------------------------------------------------------------------------

	/**
	 * This method initializes jJPanelConst	
	 * 	
	 * @return javax.swing.JPanel
	 */
	private JPanel getJPanelConst() {
		if (jPanelConst == null) {
			jPanelConst = new JPanel();
			jPanelConst.setLayout(new BorderLayout());		
			jLabelConst = new JLabel("Const: ");
			jLabelConst.setPreferredSize(new Dimension(50, 22));
			jLabelConst.setHorizontalAlignment(JLabel.RIGHT);
			SpinnerModel sModel = new SpinnerNumberModel(127, 0, 255, 1); //init, min, max, step
			jSpinnerConst = new JSpinner(sModel);
			jSpinnerConst.setPreferredSize(new Dimension(60, 22));
			jSpinnerConst.addChangeListener(this);
			JSpinner.DefaultEditor defEditor = (JSpinner.DefaultEditor)jSpinnerConst.getEditor()  ;
			JFormattedTextField ftf = defEditor.getTextField() ;
			jFormattedTextFieldConst = ftf;
			InternationalFormatter intFormatter = (InternationalFormatter)ftf.getFormatter() ;
			DecimalFormat decimalFormat = (DecimalFormat)intFormatter.getFormat() ;
			decimalFormat.applyPattern("#");  //decimalFormat.applyPattern("#,##0.0")  ;		
			jPanelConst.add(jLabelConst, 	 BorderLayout.WEST);
			jPanelConst.add(jSpinnerConst, BorderLayout.CENTER);			
		}
		return jPanelConst;
	}
	/**
	 * This method initializes jJPanelOmega	
	 * 	
	 * @return javax.swing.JPanel
	 */
	private JPanel getJPanelOmega() {
		if (jPanelOmega == null) {
			jPanelOmega = new JPanel();
			jPanelOmega.setLayout(new BorderLayout());		
			jLabelOmega = new JLabel("Omega: ");
			jLabelOmega.setHorizontalAlignment(JLabel.RIGHT);
			jLabelOmega.setPreferredSize(new Dimension(50, 22));
			SpinnerModel sModel = new SpinnerNumberModel(0, 0, Integer.MAX_VALUE, 1); //init, min, max, step
			jSpinnerOmega = new JSpinner(sModel);
			jSpinnerOmega.setPreferredSize(new Dimension(60, 22));
			jSpinnerOmega.addChangeListener(this);
			JSpinner.DefaultEditor defEditor = (JSpinner.DefaultEditor)jSpinnerOmega.getEditor()  ;
			JFormattedTextField ftf = defEditor.getTextField() ;
			jFormattedTextFieldOmega = ftf;
			InternationalFormatter intFormatter = (InternationalFormatter)ftf.getFormatter() ;
			DecimalFormat decimalFormat = (DecimalFormat)intFormatter.getFormat() ;
			decimalFormat.applyPattern("#");  //decimalFormat.applyPattern("#,##0.0")  ;		
			jPanelOmega.add(jLabelOmega, 	 BorderLayout.WEST);
			jPanelOmega.add(jSpinnerOmega, BorderLayout.CENTER);			
		}
		return jPanelOmega;
	}
	//--------------------------------------------------------------------------------------------
	/**
	 * This method initializes the Option: 
	 * 	
	 * @return javax.swing.JRadioButtonMenuItem	
	 */
	private  JRadioButtonMenuItem getJRadioButtonMenuButt8Bit() {
		if (butt8Bit == null) {
			butt8Bit = new JRadioButtonMenuItem();
			butt8Bit.setText("8Bit");
			butt8Bit.setToolTipText("8 bit output image");
			butt8Bit.addActionListener(this);
			butt8Bit.setActionCommand("parameter");
		}
		return butt8Bit;
	}
	/**
	 * This method initializes the Option: 
	 * 	
	 * @return javax.swing.JRadioButtonMenuItem	
	 */
	private  JRadioButtonMenuItem getJRadioButtonMenuButt16Bit() {
		if (butt16Bit == null) {
			butt16Bit = new JRadioButtonMenuItem();
			butt16Bit.setText("16Bit");
			butt16Bit.setToolTipText("16 bit output image");
			butt16Bit.addActionListener(this);
			butt16Bit.setActionCommand("parameter");
		}
		return butt16Bit;
	}
	


	/**
	 * This method initializes the hidden option	
	 * 	
	 * @return javax.swing.JRadioButtonMenuItem	
	 */
	private  JRadioButtonMenuItem getJRadioButtonMenuButtOutBitHidden() {
		if (buttHiddenOutBit == null) {
			buttHiddenOutBit = new JRadioButtonMenuItem();
			buttHiddenOutBit.setText("Hidden");
			buttHiddenOutBit.setVisible(false);
		}
		return buttHiddenOutBit;
	}
	/**
	 * This method initializes jJToolBarBar	
	 * 	
	 * @return javax.swing.JToolBar	
	 */
	private   JToolBar getJToolBarOutBit() {
		if (jToolBarOutBit== null) {
			jToolBarOutBit = new JToolBar("Options");
			jToolBarOutBit.setOrientation(0); // 0 Horizontal 1 Vertical orientation
			jToolBarOutBit.add(getJRadioButtonMenuButt8Bit());
			jToolBarOutBit.add(getJRadioButtonMenuButt16Bit());
			jToolBarOutBit.add(getJRadioButtonMenuButtOutBitHidden());
			//jToolBarOutBit.addSeparator();
			this.setButtonGroupOutBit();	//Gruppieren der JRadioButtons
		}
		return jToolBarOutBit;
	}
	private  void setButtonGroupOutBit() {
		//if (ButtonGroup buttGroup == null) {
			buttGroupOutBit = new ButtonGroup();
			buttGroupOutBit.add(butt8Bit);
			buttGroupOutBit.add(butt16Bit);
			buttGroupOutBit.add(buttHiddenOutBit);
	}

	//--------------------------------------------------------------------------------------------
	public void actionPerformed(ActionEvent e) {
		//System.out.println("IqmCreateImageGUI: event e: " +e.getActionCommand());
		if ("reset".equals(e.getActionCommand())) {
			ParameterBlockJAI pb = new ParameterBlockJAI("IqmCreateImage".toLowerCase());
			IqmTools.setCurrParameterBlockJAI(pb);
			this.setParameterBlock(pb);
			this.setParameterValues();
			//this.updateIqmOperatorGUI();  //if necessary here or some lines above
			this.reset();
		}
		if ("parameter".equals(e.getActionCommand())) {
			if (buttConst.isSelected()){
				jSpinnerConst.setEnabled(true);
			}else{
				jSpinnerConst.setEnabled(false);
			}
			if (buttSin.isSelected() || buttCos.isSelected()){
				jSpinnerOmega.setEnabled(true);
			}else{
				jSpinnerOmega.setEnabled(false);
			}
						
			this.setParameterBlock();
			//this.updateIqmOperatorGUI();  //if necessary here or some lines above
		}
	
		//preview if selected
		if (this.isAutoPreviewSelected()){
			this.showPreview();
		}

	}

	//-------------------------------------------------------------------------------------------------
	@Override
	public void stateChanged(ChangeEvent e) {	
	
		int width  = ((Number)jSpinnerWidth.getValue()).intValue();
		int height = ((Number)jSpinnerHeight.getValue()).intValue();

		int c     = ((Number)jSpinnerConst.getValue()).intValue();
		int omega = ((Number)jSpinnerOmega.getValue()).intValue();
	
		if (jSpinnerWidth  == e.getSource()) {
		}
		if (jSpinnerHeight  == e.getSource()) {
		}
		this.setParameterBlock();
		//this.updateIqmOperatorGUI();  //if necessary here or some lines above
		
		//preview if selected
		if (this.isAutoPreviewSelected()){
			this.showPreview();
		}
		
	}


	//-------------------------------------------------------------------------------------------------
	public static void main() {

		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				IqmCreateImageGUI gui = new IqmCreateImageGUI();
				gui.createIqmOperatorGUI();

			}
		});
	}
	
}//END
